import 'package:flutter/material.dart';
import 'padding_test_route.dart'; // 导入PaddingTestRoute

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Padding Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        fontFamily: 'Microsoft YaHei', // 推荐使用支持中文的字体
      ),
      home: const MyHomePage(title: 'Flutter Padding 示例'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            // 知识点介绍
            Text(
              'Padding 组件知识点简介',
              style: Theme.of(context).textTheme.titleLarge,
            ),
            const SizedBox(height: 12),
            const Text(
              'Padding 是 Flutter 中用于给子组件四周添加内边距的组件。'
              '\n常用的 EdgeInsets 构造方式有：\n'
              '• EdgeInsets.all(double)：四个方向相同的填充\n'
              '• EdgeInsets.only(...)：分别指定某些方向的填充\n'
              '• EdgeInsets.symmetric(...)：水平或垂直方向填充\n'
              '• EdgeInsets.fromLTRB(left, top, right, bottom)：分别指定四个方向\n',
              style: TextStyle(fontSize: 16),
            ),
            const Divider(height: 32),
            const Text('你已点击按钮的次数：'),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            const SizedBox(height: 32),
            Center(
              child: ElevatedButton.icon(
                icon: const Icon(Icons.padding),
                label: const Text('查看 Padding 示例'),
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
                  textStyle: const TextStyle(fontSize: 18),
                ),
                onPressed: () {
                  // 跳转到PaddingTestRoute页面
                  Navigator.push(
                    context,
                    MaterialPageRoute(builder: (context) => const PaddingTestRoute()),
                  );
                },
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: '自增',
        child: const Icon(Icons.add),
      ),
    );
  }
}
